$(function () {
    //广告轮播参数设置
    layui.use(['carousel', 'form'], function () {
        var carousel = layui.carousel
            , form = layui.form;

        //设定各种参数
        var ins3 = carousel.render({
            elem: '#test3',
            width: '760px',
            height: '215px',
            interval: 3000
        });
    });

    //查询任务
    pgSelTask("1","grade","desc");

    //查询好人
    selGoodman("7");

    //查询公告
    selNotice();

    //查询session中的用户
    selSessionUser();
});


//查询任务详情
function selTaskInfo(op) {
    var id = $(op).parents(".task").find(".task-id").text();
    $.ajax({
        type: 'post',
        url: ctx + "/selTaskInfo",   //提交到的url
        cache: false,
        data: {"id":id},    //提交的参数
        dataType: '',
        success: function (data) {
            if(data != null){
                alert("跳转失败");
            }else{
                alert("查询失败");
            }
        },
        error: function (data) {
            alert("查询失败！");
        }
    });
}


//用户头像的悬浮样式
function picOverStyle() {
    $("#myinfo").css("display","block");
}
//用户头像的悬浮样式
function picOutStyle() {
    $("#myinfo").css("display","none");
}


//查询session中的用户
function selSessionUser() {
    $.ajax({
        type: 'post',
        url: ctx + "/selSessionUser",   //提交到的url
        cache: false,
        data: {},    //提交的参数
        dataType: '',
        success: function (data) {
            if (null == data || "" == data) {
                $("#login-regist-text").css("display","block");
                $("#mypic").css("display","none");
            }else {
                $("#login-regist-text").css("display","none");
                $("#mypic").css({"display":"block","background-image": "url(\""+ctx+"/"+data.pic+"\")"});
                $("#mynickname span").text(data.nickname);
                $("#myprofession span").text(data.profession);
                $("#mybalance span").text("余额："+data.balance);
                if(null != data.noreadnum && "" != data.noreadnum && 0 < Number(data.noreadnum) && 99 >= Number(data.noreadnum)){
                    $("#noread").css("display","block");
                    $("#noread").text(data.noreadnum);
                }else if(99 < Number(data.noreadnum)){
                    $("#noread").css("display","block");
                    $("#noread").text("99");
                }
            }
        },
        error: function (data) {
            alert("查询失败！");
        }
    });
}


//查询公告
function selNotice() {
    $.ajax({
        type: 'post',
        url: ctx + "/selNotice",   //提交到的url
        cache: false,
        data: {},    //提交的参数
        dataType: '',
        success: function (data) {
            $("#notice-text").html(data.content);
            $("#notice-time").html("------&nbsp;"+data.time.substr(0,19));
        },
        error: function (data) {
            alert("公告查询失败！");
        }
    });
}

//好人查询
function selGoodman(date) {
    $.ajax({
        type: 'post',
        url: ctx + "/selGoodman",   //提交到的url
        cache: false,
        data: {"date": date},    //提交的参数
        dataType: '',
        success: function (data) {
            // alert("查询成功！");
            $("#goodman-centent").html("");
            $.each(data, function (index, item) {
                if(index == 0){
                    var goodman = "<div class=\"goodman1\" onmouseenter=\"boxOverStyle(this)\" onmouseleave=\"boxOutStyle(this)\">\n" +
                        "                        <div class=\"goodman-no1\">1</div>\n" +
                        "                        <div class=\"goodman-center1\">\n" +
                        "                            <div class=\"goodman-pic1\"></div>\n" +
                        "                            <div class=\"goodman-name1\"><span>"+item.nickname+"</span></div>\n" +
                        "                        </div>\n" +
                        "                        <div class=\"goodman-condition1\" title=\"帮助次数\">"+item.cardnum+"</div>\n" +
                        "                    </div>";
                    $("#goodman-centent").append(goodman);
                    $(".goodman-pic1:last").css("background-image", "url(\""+ctx+"/" + item.pic + "\")");
                }else if(index == 1){
                    var goodman = "<div class=\"goodman2\" onmouseenter=\"boxOverStyle(this)\" onmouseleave=\"boxOutStyle(this)\">\n" +
                        "                        <div class=\"goodman-no2\">2</div>\n" +
                        "                        <div class=\"goodman-center2\">\n" +
                        "                            <div class=\"goodman-pic2\"></div>\n" +
                        "                            <div class=\"goodman-name2\"><span>"+item.nickname+"</span></div>\n" +
                        "                        </div>\n" +
                        "                        <div class=\"goodman-condition2\" title=\"帮助次数\">"+item.cardnum+"</div>\n" +
                        "                    </div>";
                    $("#goodman-centent").append(goodman);
                    $(".goodman-pic2:last").css("background-image", "url(\""+ctx+"/" + item.pic + "\")");
                }else if(index == 2){
                    var goodman = "<div class=\"goodman3\" onmouseenter=\"boxOverStyle(this)\" onmouseleave=\"boxOutStyle(this)\">\n" +
                        "                        <div class=\"goodman-no3\">3</div>\n" +
                        "                        <div class=\"goodman-center3\">\n" +
                        "                            <div class=\"goodman-pic3\"></div>\n" +
                        "                            <div class=\"goodman-name3\"><span>"+item.nickname+"</span></div>\n" +
                        "                        </div>\n" +
                        "                        <div class=\"goodman-condition3\" title=\"帮助次数\">"+item.cardnum+"</div>\n" +
                        "                    </div>";
                    $("#goodman-centent").append(goodman);
                    $(".goodman-pic3:last").css("background-image", "url(\""+ctx+"/" + item.pic + "\")");
                }else if(index != 0 && index != 1 && index != 2 ){
                    var goodman = "<div class=\"goodman\" onmouseenter=\"boxOverStyle(this)\" onmouseleave=\"boxOutStyle(this)\">\n" +
                        "                        <div class=\"goodman-no\"></div>\n" +
                        "                        <div class=\"goodman-center\">\n" +
                        "                            <div class=\"goodman-pic\"></div>\n" +
                        "                            <div class=\"goodman-name\"><span>"+item.nickname+"</span></div>\n" +
                        "                        </div>\n" +
                        "                        <div class=\"goodman-condition\" title=\"帮助次数\">"+item.cardnum+"</div>\n" +
                        "                    </div>";
                    $("#goodman-centent").append(goodman);
                    $(".goodman-pic:last").css("background-image", "url(\""+ctx+"/" + item.pic + "\")");
                    $(".goodman-no:last").css("background-image", "url(\""+ctx+"/img/"+(index+1)+".png\")");
                }
            });
            if(data.length == 1){
                $(".goodman1").css({"border-bottom-left-radius": "5px","border-bottom-right-radius": "5px"});
            }else if(data.length == 2){
                $(".goodman2").css({"border-bottom-left-radius": "5px","border-bottom-right-radius": "5px"});
            }else if(data.length == 3){
                $(".goodman3").css({"border-bottom-left-radius": "5px","border-bottom-right-radius": "5px"});
            }else if(data.length > 3){
                $(".goodman:last").css({"border-bottom-left-radius": "5px","border-bottom-right-radius": "5px"});
            }
        },
        error: function (data) {
            alert("好人查询失败！");
        }
    });
}


//设置任务时间
function settime(milliSecond) {
    var starttime = milliSecond.replace(new RegExp("-","gm"),"/");
    var starttimeHaoMiao = (new Date(starttime)).getTime(); //得到毫秒数
    var timestamp = new Date().getTime();
    var time = timestamp - starttimeHaoMiao;
    if (time >= 0 && time < 1000 * 60) {
        $(".task-text-time:last").text("刚刚");
    } else if (time >= 1000 * 60 * 1 && time < 1000 * 60 * 2) {
        $(".task-text-time:last").text("1分钟前");
    } else if (time >= 1000 * 60 * 2 && time < 1000 * 60 * 3) {
        $(".task-text-time:last").text("2分钟前");
    } else if (time >= 1000 * 60 * 3 && time < 1000 * 60 * 4) {
        $(".task-text-time:last").text("3分钟前");
    } else if (time >= 1000 * 60 * 4 && time < 1000 * 60 * 5) {
        $(".task-text-time:last").text("4分钟前");
    } else if (time >= 1000 * 60 * 5 && time < 1000 * 60 * 6) {
        $(".task-text-time:last").text("5分钟前");
    } else if (time >= 1000 * 60 * 6 && time < 1000 * 60 * 7) {
        $(".task-text-time:last").text("6分钟前");
    } else if (time >= 1000 * 60 * 7 && time < 1000 * 60 * 8) {
        $(".task-text-time:last").text("7分钟前");
    } else if (time >= 1000 * 60 * 8 && time < 1000 * 60 * 9) {
        $(".task-text-time:last").text("8分钟前");
    } else if (time >= 1000 * 60 * 9 && time < 1000 * 60 * 10) {
        $(".task-text-time:last").text("9分钟前");
    } else if (time >= 1000 * 60 * 10 && time < 1000 * 60 * 11) {
        $(".task-text-time:last").text("10分钟前");
    } else if (time >= 1000 * 60 * 11 && time < 1000 * 60 * 12) {
        $(".task-text-time:last").text("11分钟前");
    } else if (time >= 1000 * 60 * 12 && time < 1000 * 60 * 13) {
        $(".task-text-time:last").text("12分钟前");
    } else if (time >= 1000 * 60 * 13 && time < 1000 * 60 * 14) {
        $(".task-text-time:last").text("13分钟前");
    } else if (time >= 1000 * 60 * 14 && time < 1000 * 60 * 15) {
        $(".task-text-time:last").text("14分钟前");
    } else if (time >= 1000 * 60 * 15 && time < 1000 * 60 * 16) {
        $(".task-text-time:last").text("15分钟前");
    } else if (time >= 1000 * 60 * 16 && time < 1000 * 60 * 17) {
        $(".task-text-time:last").text("16分钟前");
    } else if (time >= 1000 * 60 * 17 && time < 1000 * 60 * 18) {
        $(".task-text-time:last").text("17分钟前");
    } else if (time >= 1000 * 60 * 18 && time < 1000 * 60 * 19) {
        $(".task-text-time:last").text("18分钟前");
    } else if (time >= 1000 * 60 * 19 && time < 1000 * 60 * 20) {
        $(".task-text-time:last").text("19分钟前");
    } else if (time >= 1000 * 60 * 20 && time < 1000 * 60 * 21) {
        $(".task-text-time:last").text("20分钟前");
    } else if (time >= 1000 * 60 * 21 && time < 1000 * 60 * 22) {
        $(".task-text-time:last").text("21分钟前");
    } else if (time >= 1000 * 60 * 22 && time < 1000 * 60 * 23) {
        $(".task-text-time:last").text("22分钟前");
    } else if (time >= 1000 * 60 * 23 && time < 1000 * 60 * 24) {
        $(".task-text-time:last").text("23分钟前");
    } else if (time >= 1000 * 60 * 24 && time < 1000 * 60 * 25) {
        $(".task-text-time:last").text("24分钟前");
    } else if (time >= 1000 * 60 * 25 && time < 1000 * 60 * 26) {
        $(".task-text-time:last").text("25分钟前");
    } else if (time >= 1000 * 60 * 26 && time < 1000 * 60 * 27) {
        $(".task-text-time:last").text("26分钟前");
    } else if (time >= 1000 * 60 * 27 && time < 1000 * 60 * 28) {
        $(".task-text-time:last").text("27分钟前");
    } else if (time >= 1000 * 60 * 28 && time < 1000 * 60 * 29) {
        $(".task-text-time:last").text("28分钟前");
    } else if (time >= 1000 * 60 * 29 && time < 1000 * 60 * 30) {
        $(".task-text-time:last").text("29分钟前");
    } else if (time >= 1000 * 60 * 30 && time < 1000 * 60 * 31) {
        $(".task-text-time:last").text("30分钟前");
    } else if (time >= 1000 * 60 * 31 && time < 1000 * 60 * 32) {
        $(".task-text-time:last").text("31分钟前");
    } else if (time >= 1000 * 60 * 32 && time < 1000 * 60 * 33) {
        $(".task-text-time:last").text("32分钟前");
    } else if (time >= 1000 * 60 * 33 && time < 1000 * 60 * 34) {
        $(".task-text-time:last").text("33分钟前");
    } else if (time >= 1000 * 60 * 34 && time < 1000 * 60 * 35) {
        $(".task-text-time:last").text("34分钟前");
    } else if (time >= 1000 * 60 * 35 && time < 1000 * 60 * 36) {
        $(".task-text-time:last").text("35分钟前");
    } else if (time >= 1000 * 60 * 36 && time < 1000 * 60 * 37) {
        $(".task-text-time:last").text("36分钟前");
    } else if (time >= 1000 * 60 * 37 && time < 1000 * 60 * 38) {
        $(".task-text-time:last").text("37分钟前");
    } else if (time >= 1000 * 60 * 38 && time < 1000 * 60 * 39) {
        $(".task-text-time:last").text("38分钟前");
    } else if (time >= 1000 * 60 * 39 && time < 1000 * 60 * 40) {
        $(".task-text-time:last").text("39分钟前");
    } else if (time >= 1000 * 60 * 40 && time < 1000 * 60 * 41) {
        $(".task-text-time:last").text("40分钟前");
    } else if (time >= 1000 * 60 * 41 && time < 1000 * 60 * 42) {
        $(".task-text-time:last").text("41分钟前");
    } else if (time >= 1000 * 60 * 42 && time < 1000 * 60 * 43) {
        $(".task-text-time:last").text("42分钟前");
    } else if (time >= 1000 * 60 * 43 && time < 1000 * 60 * 44) {
        $(".task-text-time:last").text("43分钟前");
    } else if (time >= 1000 * 60 * 44 && time < 1000 * 60 * 45) {
        $(".task-text-time:last").text("44分钟前");
    } else if (time >= 1000 * 60 * 45 && time < 1000 * 60 * 46) {
        $(".task-text-time:last").text("45分钟前");
    } else if (time >= 1000 * 60 * 46 && time < 1000 * 60 * 47) {
        $(".task-text-time:last").text("46分钟前");
    } else if (time >= 1000 * 60 * 47 && time < 1000 * 60 * 48) {
        $(".task-text-time:last").text("47分钟前");
    } else if (time >= 1000 * 60 * 48 && time < 1000 * 60 * 49) {
        $(".task-text-time:last").text("48分钟前");
    } else if (time >= 1000 * 60 * 49 && time < 1000 * 60 * 50) {
        $(".task-text-time:last").text("49分钟前");
    } else if (time >= 1000 * 60 * 50 && time < 1000 * 60 * 51) {
        $(".task-text-time:last").text("50分钟前");
    } else if (time >= 1000 * 60 * 51 && time < 1000 * 60 * 52) {
        $(".task-text-time:last").text("51分钟前");
    } else if (time >= 1000 * 60 * 52 && time < 1000 * 60 * 53) {
        $(".task-text-time:last").text("52分钟前");
    } else if (time >= 1000 * 60 * 53 && time < 1000 * 60 * 54) {
        $(".task-text-time:last").text("53分钟前");
    } else if (time >= 1000 * 60 * 54 && time < 1000 * 60 * 55) {
        $(".task-text-time:last").text("54分钟前");
    } else if (time >= 1000 * 60 * 55 && time < 1000 * 60 * 56) {
        $(".task-text-time:last").text("55分钟前");
    } else if (time >= 1000 * 60 * 56 && time < 1000 * 60 * 57) {
        $(".task-text-time:last").text("56分钟前");
    } else if (time >= 1000 * 60 * 57 && time < 1000 * 60 * 58) {
        $(".task-text-time:last").text("57分钟前");
    } else if (time >= 1000 * 60 * 58 && time < 1000 * 60 * 59) {
        $(".task-text-time:last").text("58分钟前");
    } else if (time >= 1000 * 60 * 59 && time < 1000 * 60 * 60) {
        $(".task-text-time:last").text("59分钟前");
    } else if (time >= 1000 * 60 * 60 * 1 && time < 1000 * 60 * 60 * 2) {
        $(".task-text-time:last").text("1小时前");
    } else if (time >= 1000 * 60 * 60 * 2 && time < 1000 * 60 * 60 * 3) {
        $(".task-text-time:last").text("2小时前");
    } else if (time >= 1000 * 60 * 60 * 3 && time < 1000 * 60 * 60 * 4) {
        $(".task-text-time:last").text("3小时前");
    } else if (time >= 1000 * 60 * 60 * 4 && time < 1000 * 60 * 60 * 5) {
        $(".task-text-time:last").text("4小时前");
    } else if (time >= 1000 * 60 * 60 * 5 && time < 1000 * 60 * 60 * 6) {
        $(".task-text-time:last").text("5小时前");
    } else if (time >= 1000 * 60 * 60 * 6 && time < 1000 * 60 * 60 * 7) {
        $(".task-text-time:last").text("6小时前");
    } else if (time >= 1000 * 60 * 60 * 7 && time < 1000 * 60 * 60 * 8) {
        $(".task-text-time:last").text("7小时前");
    } else if (time >= 1000 * 60 * 60 * 8 && time < 1000 * 60 * 60 * 9) {
        $(".task-text-time:last").text("8小时前");
    } else if (time >= 1000 * 60 * 60 * 9 && time < 1000 * 60 * 60 * 10) {
        $(".task-text-time:last").text("9小时前");
    } else if (time >= 1000 * 60 * 60 * 10 && time < 1000 * 60 * 60 * 11) {
        $(".task-text-time:last").text("10小时前");
    } else if (time >= 1000 * 60 * 60 * 11 && time < 1000 * 60 * 60 * 12) {
        $(".task-text-time:last").text("11小时前");
    } else if (time >= 1000 * 60 * 60 * 12 && time < 1000 * 60 * 60 * 13) {
        $(".task-text-time:last").text("12小时前");
    } else if (time >= 1000 * 60 * 60 * 13 && time < 1000 * 60 * 60 * 14) {
        $(".task-text-time:last").text("13小时前");
    } else if (time >= 1000 * 60 * 60 * 14 && time < 1000 * 60 * 60 * 15) {
        $(".task-text-time:last").text("14小时前");
    } else if (time >= 1000 * 60 * 60 * 15 && time < 1000 * 60 * 60 * 16) {
        $(".task-text-time:last").text("15小时前");
    } else if (time >= 1000 * 60 * 60 * 16 && time < 1000 * 60 * 60 * 17) {
        $(".task-text-time:last").text("16小时前");
    } else if (time >= 1000 * 60 * 60 * 17 && time < 1000 * 60 * 60 * 18) {
        $(".task-text-time:last").text("17小时前");
    } else if (time >= 1000 * 60 * 60 * 18 && time < 1000 * 60 * 60 * 19) {
        $(".task-text-time:last").text("18小时前");
    } else if (time >= 1000 * 60 * 60 * 19 && time < 1000 * 60 * 60 * 20) {
        $(".task-text-time:last").text("19小时前");
    } else if (time >= 1000 * 60 * 60 * 20 && time < 1000 * 60 * 60 * 21) {
        $(".task-text-time:last").text("20小时前");
    } else if (time >= 1000 * 60 * 60 * 21 && time < 1000 * 60 * 60 * 22) {
        $(".task-text-time:last").text("21小时前");
    } else if (time >= 1000 * 60 * 60 * 22 && time < 1000 * 60 * 60 * 23) {
        $(".task-text-time:last").text("22小时前");
    } else if (time >= 1000 * 60 * 60 * 23 && time < 1000 * 60 * 60 * 24) {
        $(".task-text-time:last").text("23小时前");
    } else if (time >= 1000 * 60 * 60 * 24 * 1 && time < 1000 * 60 * 60 * 24 * 2) {
        $(".task-text-time:last").text("昨天");
    } else if (time >= 1000 * 60 * 60 * 24 * 2 && time < 1000 * 60 * 60 * 24 * 3) {
        $(".task-text-time:last").text("前天");
    } else if (time >= 1000 * 60 * 60 * 24 * 3 || time < 0) {
        var otime = getMyDate(milliSecond);
        $(".task-text-time:last").text("" + otime + "");
    }
}
//计算任务时间
function getMyDate(str) {
    var oDate = new Date(str),
        oYear = oDate.getFullYear(),
        oMonth = oDate.getMonth() + 1,
        oDay = oDate.getDate(),
        oHour = oDate.getHours(),
        oMin = oDate.getMinutes(),
        oSen = oDate.getSeconds(),
        oTime = oYear + '-' + addZero(oMonth) + '-' + addZero(oDay);
    return oTime;
}
//给时间加0
function addZero(num) {
    if (parseInt(num) < 10) {
        num = '0' + num;
    }
    return num;
}


var order = "grade";
var by = "desc";
//点击‘加载更多’的动画
function clickMore() {
    $("#box-page").css("display", "none");
    $("#load-img").css("display", "block");
    var pg = Number($("#page-now").text()) + 1;
    $.ajax({
        type: 'post',
        url: ctx + "/pgSelTask",   //提交到的url
        cache: false,
        data: {"pg": pg,"order":order,"by":by},    //提交的参数
        dataType: '',
        success: function (data) {
            // alert("查询成功！");
            setTimeout(function () {
                if (data.length <= 0) {
                    $("#box-page").text("没有更多");
                    $("#box-page").css("display", "block");
                    $("#load-img").css("display", "none");
                    setTimeout(function () {
                        $("#help-bottom").css("display", "none");
                    }, 1500);
                } else {
                    $.each(data, function (index, item) {
                        var task = "<div class=\"task\" onmouseenter=\"boxOverStyle(this)\" onmouseleave=\"boxOutStyle(this)\">\n" +
                            "                        <div class=\"task-id\">" + item.id + "</div>\n" +
                            "                        <div class=\"pic\"></div>\n" +
                            "                        <div class=\"task-text\">\n" +
                            "                            <div class=\"task-text-top\">\n" +
                            "                                <div class=\"task-text-type\">" + item.type.name + "</div>\n" +
                            "                                <div class=\"task-text-title\"><a href='selTaskInfo?id="+item.id+"'><span>" + item.title + "</span></a></div>\n" +
                            "                                <div class=\"task-text-cardnum\" title=\"好人卡数量\">card：" + item.cardnum + "</div>\n" +
                            "                            </div>\n" +
                            "                            <div class=\"task-text-bottom\">\n" +
                            "                                <div class=\"task-text-user\">" + item.user.nickname + "</div>\n" +
                            "                                <div class=\"task-text-time\"></div>\n" +
                            "                                <div class=\"task-text-used\" title=\"任务所需人数\"></div>\n" +
                            "                                <div class=\"task-text-commentnum\" title=\"评论数量\"><img src=\""+ctx+"/img/comment.png\" />" + item.commentNum + "</div>\n" +
                            "                            </div>\n" +
                            "                        </div>\n" +
                            "                    </div>";
                        $("#help-centent").append(task);
                        $(".pic:last").css("background-image", "url(\""+ctx+"/" + item.user.pic + "\")");
                        if (item.usernum > 0) {
                            $(".task-text-used:last").text("还需" + item.usernum + "人");
                        } else {
                            $(".task-text-used:last").text("人员已满");
                        }
                        settime(item.createtime);
                    });
                    $("#page-now").text(pg);
                }
                $("#box-page").css("display", "block");
                $("#load-img").css("display", "none");
            }, 500);
        },
        error: function (data) {
            alert("查询失败！");
            $("#box-page").css("display", "block");
            $("#load-img").css("display", "none");
        }
    });
}


//点赞动画
function clickLike(op) {
    var img = $(op).children("img").attr("src");
    if (img == ctx + "/img/like0.png") {
        $(op).children("img").attr("src", "img/like1.png");
        var txt = $(op).children("span").text();
        var num = Number(txt);
        $(op).children("span").text(num + 1);
    } else {
        $(op).children("img").attr("src", "img/like0.png");
        var txt = $(op).children("span").text();
        var num = Number(txt);
        $(op).children("span").text(num - 1);
    }
}


//任务box和好人box的悬浮样式
function boxOverStyle(op) {
    var cla = $(op).attr("class");
    if (cla != "goodman1" && cla != "goodman2" && cla != "goodman3") {
        var cla2 = $(op).prev().attr("class");
        if (cla2 != "goodman3") {
            $(op).css({"border-bottom": "none"});
            $(op).css({"margin-bottom": "1px"});
            $(op).prev().css({"border-bottom": "none"});
            $(op).prev().css({"margin-bottom": "1px"});
        }
        var cla3 = $(op).next().attr("class");
        if(cla3 == "" || cla3 == null){
            $(op).css({"box-shadow": "0px 0px 5px 0px rgb(175, 175, 175)", "z-index": "101"});
        }else{
            $(op).css({"box-shadow": "0px 0px 4px 0px rgb(200, 200, 200)", "z-index": "101"});
        }
    } else {
        $(op).css({"box-shadow": "0px 0px 6px 0px rgb(150, 150, 150)", "z-index": "101"});
    }
}
//任务box和好人box的悬浮样式2
function boxOutStyle(op) {
    var cla = $(op).attr("class");
    var cla2 = $(op).prev().attr("class");
    if (cla != "goodman1" && cla != "goodman2" && cla != "goodman3" && cla2 != "goodman3") {
        $(op).css({"border-bottom": "1px solid rgb(230, 230, 230)"});
        $(op).css({"margin-bottom": "0px"});
        $(op).prev().css({"border-bottom": "1px solid rgb(230, 230, 230)"});
        $(op).prev().css({"margin-bottom": "0px"});
    }
    $(op).css({"box-shadow": "0px 0px 0px 0px rgb(255, 255, 255)", "z-index": "100"});
}

//周榜月榜悬浮样式
function weekMonthOverStyle(op) {
    $(op).css("color", "rgb(0, 160, 160)");
}
//周榜月榜悬浮样式2
function weekMonthOutStyle(op) {
    var c1 = $(op).prev().prev().css("color");
    var c2 = $(op).next().next().css("color");
    if (c1 == "rgb(0, 160, 160)" || c2 == "rgb(0, 160, 160)") {
        $(op).css("color", "rgb(0, 0, 0)");
    }
}


//周榜月榜点击切换动画
function weekMonthClick(op) {
    $(".sort-text2").css("color", "black");
    $(".sort-text2-first").css("color", "black");
    $(op).css("color", "rgb(0, 160, 160)");
    var text = $(op).children("span").text();
    if (text == "周榜") {
        selGoodman("7");
    }else{
        selGoodman("30");
    }
}


var i = 0;
//上下标的悬浮样式
function updownOverStyle(op) {
    var nowimg = $(op).children(".sort-img").attr("src");
    if (nowimg == ctx + "/img/sort-null.png") {
        $(op).children(".sort-img").attr("src", ctx + "/img/sort-middle.png");
        $(op).css("color","rgb(0,140,140)");
    }else if((nowimg == "" || nowimg == null) && i == 0){
        $(op).css("color","rgb(0,140,140)");
        i = 1;
    }
}
//上下标的悬浮样式2
function updownOutStyle(op) {
    var nowimg = $(op).children(".sort-img").attr("src");
    if (nowimg == ctx + "/img/sort-middle.png") {
        $(op).children(".sort-img").attr("src", ctx + "/img/sort-null.png");
        $(op).css("color","rgb(0,0,0)");
    }else if((nowimg == "" || nowimg == null) && i == 1){
        $(op).css("color","rgb(0,0,0)");
        i = 0;
    }
}


//上下标的点击样式
function updownClickStyle(op) {
    var nowtext = $(op).children("span").text();
    var nowimg = $(op).children(".sort-img").attr("src");
    if(nowtext == "时间"){
        order = "createtime";
    }else if(nowtext == "好人卡"){
        order = "cardnum";
    }
    $("#page-now").text("1");
    $(".sort-text").css("color", "rgb(0,0,0)");
    $(".sort-text").children(".sort-img").attr("src", ctx + "/img/sort-null.png");
    if (nowimg == ctx + "/img/sort-middle.png") {
        $(op).css("color","rgb(0,140,140)");
        $(op).children(".sort-img").attr("src", ctx + "/img/sort-top.png");
        by = "asc";
        i = 0;
    } else if (nowimg == ctx + "/img/sort-top.png") {
        $(op).css("color","rgb(0,140,140)");
        $(op).children(".sort-img").attr("src", ctx + "/img/sort-bottom.png");
        by = "desc";
        i = 0;
    } else if (nowimg == ctx + "/img/sort-bottom.png") {
        $(op).css("color","rgb(0,0,0)");
        $(op).children(".sort-img").attr("src", ctx + "/img/sort-middle.png");
        order = "grade";
        i = 0;
    } else if (nowimg == "" || nowimg == null) {
        $(op).children(".sort-img").attr("src", ctx + "/img/sort-middle.png");
        if(i == 1){
            $(op).css("color","rgb(0, 140, 140)");
            order = "finish";
            i = 2;
        }else{
            $(op).css("color","rgb(0, 0, 0)");
            order = "grade";
            i = 1;
        }
    }
    $("#box-page").text("加载更多");
    $("#help-bottom").css("display", "block");
    $("#box-page").css("display", "block");
    $("#load-img").css("display", "none");
    pgSelTask("1",order,by);
}


//任务查询
function pgSelTask(pg,order,by) {
    $("#box-page").css("display", "none");
    $("#load-img").css("display", "block");
    $.ajax({
        type: 'post',
        url: ctx + "/pgSelTask",   //提交到的url
        cache: false,
        data: {"pg": pg,"order":order,"by":by},    //提交的参数
        dataType: '',
        success: function (data) {
            // alert("查询成功！");
            $("#help-centent").html("");
            $.each(data, function (index, item) {
                var task = "<div class=\"task\" onmouseenter=\"boxOverStyle(this)\" onmouseleave=\"boxOutStyle(this)\">\n" +
                    "                        <div class=\"task-id\">" + item.id + "</div>\n" +
                    "                        <div class=\"pic\"></div>\n" +
                    "                        <div class=\"task-text\">\n" +
                    "                            <div class=\"task-text-top\">\n" +
                    "                                <div class=\"task-text-type\">" + item.type.name + "</div>\n" +
                    "                                <div class=\"task-text-title\"><a href='selTaskInfo?id="+item.id+"'><span>" + item.title + "</span></a></div>\n" +
                    "                                <div class=\"task-text-cardnum\" title=\"好人卡数量\">card：" + item.cardnum + "</div>\n" +
                    "                            </div>\n" +
                    "                            <div class=\"task-text-bottom\">\n" +
                    "                                <div class=\"task-text-user\">" + item.user.nickname + "</div>\n" +
                    "                                <div class=\"task-text-time\"></div>\n" +
                    "                                <div class=\"task-text-used\" title=\"任务所需人数\"></div>\n" +
                    "                                <div class=\"task-text-commentnum\" title=\"评论数量\"><img src=\""+ctx+"/img/comment.png\" />" + item.commentNum + "</div>\n" +
                    "                            </div>\n" +
                    "                        </div>\n" +
                    "                    </div>";
                $("#help-centent").append(task);
                $(".pic:last").css("background-image", "url(\""+ctx+"/" + item.user.pic + "\")");
                if (item.usernum > 0) {
                    $(".task-text-used:last").text("还需" + item.usernum + "人");
                } else {
                    $(".task-text-used:last").text("人员已满");
                }
                settime(item.createtime.substr(0,19));
            });
        },
        error: function (data) {
            alert("任务查询失败！");
        }
    });
    $("#box-page").css("display", "block");
    $("#load-img").css("display", "none");
}
[ctx + '/newrelease.jsp', 'no']
//iframe窗
function openIframe () {
    var index = layer.open({
        type: 2,
        content: [ctx + '/newrelease.jsp', 'no'],
        area: ['320px', '195px'],
        maxmin: true
    });
    layer.full(index);
}